/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.common.constant.evaluation;

import org.apache.commons.lang3.StringUtils;

/**
 * 检查项（D/A/K）测评结果
 * @author zpy
 * @version 1.0.0
 */
public enum EvaluationResult {
    /**未判断**/
    DEFAULT(0,""),
    /**符合**/
    MATCH(1,"符合"),
    /**不符合**/
    NOT_MATCH(3,"不符合"),
    /**不适用**/
    NOT_APPLICABLE(4,"不适用");

    private final int result;
    private final String name;

    EvaluationResult(int result, String name) {
        this.result = result;
        this.name = name;
    }

    public static EvaluationResult fromResult(Integer result){
        EvaluationResult data = DEFAULT;
        for(EvaluationResult tt :EvaluationResult.values()){
            if(tt.result == result){
                data = tt;
                break;
            }
        }
        return data;
    }

    public static EvaluationResult fromName(String name){
        EvaluationResult data = DEFAULT;
        for(EvaluationResult tt :EvaluationResult.values()){
            if(StringUtils.equals(tt.getName(),name)){
                data = tt;
                break;
            }
        }
        return data;
    }

    public int getResult(){
        return this.result;
    }

    public String getName(){
        return this.name;
    }
}